package pcloud.client.watcher;

import static org.junit.Assert.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import pcloud.client.PCloudClient;

public class ClientTest
{
	
	private PCloudClient pCloudClient;
	@Before
	public void setUp() throws Exception
	{
		pCloudClient = new PCloudClient();
		pCloudClient.startSync();

	}
	
	@Test
	public void createFileTest()
	{
		String path = "D:/pcloud/WatchTest/CreateFileTest.txt";
		File file = new File (path);
		if (file.exists() && pCloudClient.getLocalDb().get(path)==null) {
			try {
				file.createNewFile();
				FileWriter writer = new FileWriter(file);
				writer.write("This is a new file to test!");
				writer.flush();
				writer.close();
			} catch (IOException e) {
				e.printStackTrace();
				fail(e.getMessage());
			}
		}
		try {
			Thread.sleep(1000 * 60 * 5);
		} catch (InterruptedException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
		File targetFile = new File ("D:/pcloud/ftpserver/CreateFileTest.txt");
		assertTrue(targetFile.exists());
		assertTrue(targetFile.length()==27);
	}

	@After
	public void tearDown() throws Exception
	{
		pCloudClient.stopSync();
	}

}
